package com.hwy.widget.segment

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.hwy.widget.R
import com.hwy.widget.utils.DisplayUtil

class SegmentActivity : AppCompatActivity() {

    private val dataList = arrayOf("今日", "近5日", "近1月", "近3月")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_segment)

        findViewById<TabSegment>(R.id.segment)?.run {
            setAdapter(object : TabSegment.Adapter {
                override fun getItemCount(): Int {
                    return dataList.size
                }

                override fun getItem(position: Int): String {
                    return dataList[position]
                }

            })
        }

        findViewById<TabSegment>(R.id.segment2)?.run {
            segmentSlider =
                SegmentSliderIndicator(DisplayUtil.dpToPx(20), DisplayUtil.dpToPx(4), this)
            setAdapter(object : TabSegment.Adapter {
                override fun getItemCount(): Int {
                    return dataList.size
                }

                override fun getItem(position: Int): String {
                    return dataList[position]
                }
            })
            onItemClickListener = object : TabSegment.OnItemClickListener {
                override fun onItemClick(from: Int, to: Int) {
                    Log.d("TAG", "onItemClick: ${dataList[to]}")
                }
            }
        }

    }

}